package com.sanjiahantang.youjiaclient.module.complain.views.impl;

import android.content.Intent;
import android.net.Uri;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;

import com.sanjiahantang.youjiaclient.R;
import com.sanjiahantang.youjiaclient.base.BaseMvpActivity;
import com.sanjiahantang.youjiaclient.module.complain.presenters.MeComplainPresenter;
import com.sanjiahantang.youjiaclient.module.complain.views.MeComplainView;


/**
 * Created by zy on 2017/9/8.
 */

public class MeComplainActivity extends BaseMvpActivity<MeComplainView,MeComplainPresenter>
        implements MeComplainView, View.OnClickListener {
    private RadioButton rbFromMe,rbToMe;
    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private SwipeRefreshLayout refreshLayout;
    @Override
    public void showProgress() {
        refreshLayout.setRefreshing(true);
    }

    @Override
    public MeComplainPresenter initPresenter() {
        return new MeComplainPresenter();
    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_me_complain);
        refreshLayout = (SwipeRefreshLayout) findViewById(R.id.refreshLayout);
        rbFromMe = (RadioButton) findViewById(R.id.rbFromMe);
        rbToMe = (RadioButton) findViewById(R.id.rbToMe);
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("我的投诉");

        ImageView icon1 = (ImageView) findViewById(R.id.icon1);
        icon1.setVisibility(View.VISIBLE);
        icon1.setImageResource(R.drawable.i_csd);
        findViewById(R.id.flIcon1).setOnClickListener(this);
        findViewById(R.id.fl_Left).setOnClickListener(this);
        rbFromMe.setOnClickListener(this);
        rbToMe.setOnClickListener(this);
        findViewById(R.id.flFromMe).setOnClickListener(this);
        findViewById(R.id.flToMe).setOnClickListener(this);

        refreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                if (rbFromMe.isChecked()){
                    presenter.loadData($this,TYPE_FROM_ME);
                }else {
                    presenter.loadData($this,TYPE_TO_ME);
                }
            }
        });
    }

    @Override
    public void initData() {
        presenter.loadData($this,TYPE_FROM_ME);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.rbFromMe:case R.id.flFromMe:
                rbFromMe.setChecked(true);
                rbToMe.setChecked(false);
                presenter.loadData($this,TYPE_FROM_ME);
                break;
            case R.id.rbToMe:case R.id.flToMe:
                rbFromMe.setChecked(false);
                rbToMe.setChecked(true);
                presenter.loadData($this,TYPE_TO_ME);
                break;
            case R.id.flIcon1://新增投诉
                Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:666666"));
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                break;
            case R.id.fl_Left://后退
                finish();
                break;
        }
    }

    @Override
    public void loadData(RecyclerView.Adapter adapter) {
        recyclerView.setAdapter(adapter);
    }

    @Override
    public void hideProgress() {
        super.hideProgress();
        refreshLayout.setRefreshing(false);
    }
}
